package com.heima.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.admin.entity.AdSensitive;
import com.heima.admin.entity.SensitivePageDto;
import com.heima.admin.mapper.AdSensitiveMapper;
import com.heima.admin.service.AdSensitiveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import com.heima.common.dtos.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 敏感词信息表 服务实现类
 * </p>
 *
 * @author HM
 * @since 2023-05-25
 */
@Service
public class AdSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper, AdSensitive> implements AdSensitiveService {


    /*
     * 分页查询*/
    @Override
    public PageResult<AdSensitive> pageQuery(SensitivePageDto dto) {
        //设置分页参数
        Page<AdSensitive> page = new Page<>(dto.getPage(), dto.getSize());
        //设置模糊查询条件
        LambdaQueryWrapper<AdSensitive> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(dto.getSensitives()), AdSensitive::getSensitives, dto.getSensitives());

       //按照时间倒序查询
        queryWrapper.orderByAsc(AdSensitive::getCreatedTime);

        //分页查询
        Page<AdSensitive> result = this.page(page, queryWrapper);
        return new PageResult<>(dto.getPage(), dto.getSize(), result.getTotal(), result.getRecords());

    }
}
